package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.ContractFileDao;
import cn.topevery.garden.entity.po.ContractFile;
import cn.topevery.garden.entity.query.ContractFileQuery;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.CommandType;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-06
 */
@Repository
public class ContractFileDaoImpl extends BaseDaoImpl<ContractFile> implements ContractFileDao {
    @Override
    public <P extends DbCsp> List<ContractFile> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<ContractFile> listPage(ContractFileQuery query) {
        String table = "t_contract_file tcf";

        String columns = "tcf.*";
		int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tcf.c_id desc");
        sqlQueryMate
                .where(true, "tcf.c_db_status", ScriptConditionEnum.Eq, 0)
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, ContractFile.class);
    }

    @Override
    public List<ContractFile> getListByPid(Integer pid) {
        String table = "t_contract_file tpc";

        String columns = "tpc.*";

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns);
        sqlQueryMate
                .where(true, "tpc.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(true, "tpc.c_main_id", ScriptConditionEnum.Eq, pid)
        ;
        return selectList(sqlQueryMate, ContractFile.class);
    }

    @Override
    public void deleteById(Integer id) {
        String sql = "delete from t_contract_file where c_main_id = " + id;
        run(sql, CommandType.Text, dbCommand -> {
            dbCommand.executeNonQuery();
        });
    }
}
